import { Component, Vue, Watch } from 'vue-property-decorator'
import { VerifySwipe } from '@/components/index'
@Component({
    name: 'Login',
    components: {
        VerifySwipe
    }
})

export default class Login extends Vue {

    private surname = ''
    private mobile = ''
    private linkguid = window.CUSTOMP.linkguid
    private verify = ''
    private sendVal = '发送验证码'
    private num = 60
    private verificationValue = false

    private rules = {
        mobile: [{
            required: true, pattern: /^1[3456789]\d{9}$/, message: (v: string) => {
                if (v.length > 0) {
                    return '请输入正确的手机号码'
                }
                return '请填写手机号码'
            }
        }]
    }
    @Watch('verificationValue')
    onverificationValue(v: boolean) {
        console.log('验证通过')
    }
    sendCode() {
        this.timer()
        this.$refs.form.validate('mobile').then((e: any) => {
            console.log(e)
            this.postData()

        }).catch((e: any) => {
            console.log(e)
            this.num = 0
        })

    }
    timer() {
        this.num--
        this.sendVal = this.num + 'S'
        if (this.num <= 0) {
            this.num = 60
            this.sendVal = '发送验证码'
            return
        }
        setTimeout(this.timer, 1000)
    }
    postData() {
        const data = {
            surname: this.surname,
            mobile: this.mobile,
            linkguid: this.linkguid
        }
        this.$store.commit('setUser', data)
        console.log('submit', data);
        // console.log(data)
        //发送验证码
        this.$axios({
            method: 'POST',
            url: '/reg/IscRegister/formmarking/GetVerifyCode',
            data: data
        }).then((e: any) => {
            this.$toast('验证码发送成功！请查看手机短信')
        }).catch((e: any) => {
 
            console.log(e)

        })

    }
    onSubmit(values: string) {

        this.$refs.form.validate().then((e: any) => {
           this.commitLogin()

        }).catch((e: any) => {
            //  console.log(e)
        })
    }
    commitLogin() {
        const data = {
            surname: this.surname,
            mobile: this.mobile,
            linkguid: this.linkguid
        }
        this.$store.commit('setUser', data)
        this.$router.push('/personalInformation?cd=7393395C')

        this.$axios({
            method: 'POST',
            url: '/reg/IscRegister/formmarking/CheckVerifyCode',
            data: {...data,showLoading:true}
        }).then((e: any) => {

            this.$store.commit('setUser', data)
            this.$router.push('/personalInformation?cd=7393395C')
            console.log('=-===========',e)
        }).catch((e: any) => {
        
            this.$toast('验证码不正确')


        })

    }


}